<?php

class dbSocket implements socketInterface
{
	public $oBench;		//benchmark object
	private $rId;		//Connectie-id
	
	
	public function __construct ($aCfg)
	{
		$this->oBench = new benchmark();
		
		//
		//Connectie met database maken
		//
		if ($aCfg['persistancy'])
		{
			$this->rId = @mysql_pconnect($aCfg['host'], $aCfg['user'], $aCfg['pass']);
		}
		else
		{
			$this->rId = @mysql_connect($aCfg['host'], $aCfg['user'], $aCfg['pass']);
		}
		$this->oBench->add_mark('db connection');
		if ($this->rId === false)					die('connectError '.mysql_error());
		
		//
		//Database selecteren
		//
		$this->oBench->start_mark();
		if (!@mysql_select_db($aCfg['database']))	die('noDbSelected '.mysql_error());
		$this->oBench->add_mark('db selection');
		
		//
		//Setting the resultHandler for all the childmodels
		//
		dbModel::$rHandler = $this->rId;
	}
	
	
	public function __destruct ()
	{
		if ($this->rId !== false)
		{
			mysql_close($this->rId);
		}
	}
}

?>